<template>
	<Top-Page style="padding-bottom: 30rpx">
		<cu-custom bgColor="bg-gradual-white-3" :isBack="true">
			<template #content>公开信息</template>
		</cu-custom>
		<view class="list">
			<text class="li" :class="{ on: item.state }" v-for="item in baseList" :key="item.name" @click="change(item)">
				{{ item.name }}
			</text>
		</view>
		<text class="btn" @click="baseConfirm">保存</text>
	</Top-Page>
</template>

<script>
export default {
	data() {
		return {
			baseList: {
				user_name: {
					name: "姓名",
					state: 0,
				},
				identity_address: {
					name: "出生地址",
					state: 0,
				},
				identity: {
					name: "身份证号码",
					state: 0,
				},
				address: {
					name: "现住地址",
					state: 0,
				},
				school: {
					name: "曾就读过的学校",
					state: 0,
				},
				friends: {
					name: "想记忆的家人或朋友",
					state: 0,
				},
				good_at: {
					name: "学过的技能",
					state: 0,
				},
				speciality: {
					name: "现在特长",
					state: 0,
				},
				hobby: {
					name: "兴趣爱好",
					state: 0,
				},
				footprint: {
					name: "我的足迹",
					state: 0,
				},
				work_experience: {
					name: "工作经历",
					state: 0,
				},
				take_address: {
					name: "收货地址",
					state: 0,
				},
				employment_log: {
					name: "创业就业经历",
					state: 0,
				},
				lived_address: {
					name: "曾经住过的地址",
					state: 0,
				},
				previous_employer: {
					name: "曾工作单位",
					state: 0,
				},
				attended_schools: {
					name: "曾就读过的学校",
					state: 0,
				},
				mem_family_friends: {
					name: "记忆的家人或朋友",
					state: 0,
				},
				skills_learned: {
					name: "学过的技能",
					state: 0,
				},
				favorite_brand: {
					name: "喜欢的品牌",
					state: 0,
				},
			},
		}
	},
	onLoad() {
		let baseInfoConfig = uni.getStorageSync("userInfo").user_show_data
		if (baseInfoConfig) {
			for (let key in this.baseList) {
				this.baseList[key].state = baseInfoConfig[key]
			}
		}
	},
	methods: {
		change(item) {
			console.log(item)
			item.state = item.state ? 0 : 1
		},
		baseConfirm() {
			console.log(this.baseList)
			let obj = {}
			for (let key in this.baseList) {
				obj[key] = this.baseList[key].state
			}
			console.log(obj, "obj")
			uni.showLoading({
				title: "更新中",
				mask: true,
			})
			this.$api.friendApi.updateUserInfoShow(obj).then((res) => {
				console.log(res, "res.data")
				if (res.code === 0) {
					let userInfo = uni.getStorageSync("userInfo")
					userInfo.user_show_data = res.data
					for (let key in userInfo.user_show_data) {
						userInfo[key] = res.data[key]
					}
					uni.setStorageSync("userInfo", userInfo)
				}
				uni.showToast({
					title: "更新成功",
				})
			})
		},
	},
}
</script>

<style lang="scss">
// 此页面不需要关怀模式
.list {
	display: flex;
	flex-wrap: wrap;
	padding: 30rpx;
	font-size: 24rpx;
	text {
		color: #6a6a6a;
		border: 1px solid;
		padding: 24rpx;
		margin-right: 16rpx;
		border-radius: 10rpx;
		margin-bottom: 30rpx;
	}
	.on {
		background-color: #1677ff;
		color: #fff;
	}
}
.btn {
	display: block;
	margin: 30rpx;
	background-color: #1677ff;
	color: #fff;
	padding: 20rpx;
	border-radius: 10rpx;
	text-align: center;
	font-size: 24rpx;
}
</style>
